package com.huilian.tool.weixin.service;

import com.alibaba.fastjson.JSONObject;
import com.huilian.tool.common.utils.AesException;
import com.huilian.tool.weixin.enums.ActionNameEnum;
import com.huilian.tool.weixin.vo.Menu;
import org.dom4j.DocumentException;

import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * @authou 少凡
 * @Date 2019-04-12 16:04
 */
public interface WeixinService {

    /**
     * 微信开启开发者模式 配置接口
     *
     * @param request
     * @return
     */
    String openDeveloperModel(HttpServletRequest request, String token);

    /**
     * 获取 微信JsSDK 接口注入权限验证配置
     *
     * @param url
     * @param jsApiTicket
     * @return
     */
    Map<String, String> getWeiXinJsSdkConfig(String url, String jsApiTicket);


    /**
     * 微信消息管理
     *
     * @param request
     * @return
     */
    String messageManage(HttpServletRequest request)
            throws DocumentException, AesException, IOException;

    /**
     * 获取微信公众号带参二维码
     *
     * @param accessToken    微信基础服务Token
     * @param actionNameEnum
     * @param sceneId        参数
     * @param expireSeconds  有效时间可不传
     * @return
     */
    JSONObject getQrCodeParam(String accessToken, ActionNameEnum actionNameEnum, String sceneId, String... expireSeconds);

    /**
     * 创建二维码
     *
     * @param token
     * @param menu
     * @return
     */
    String createMenu(String token, Menu menu);

    /**
     * 获取基础accessToken
     *
     * @return
     */
    String getAccessToken();

    String getAccessToken(String appId, String appSecret);

    String getJsApiTicket();

    /**
     * 制作推广名片
     *
     * @param userId
     * @param nickName
     * @param headImgUrl
     * @param qrCodeUrl
     * @param fileExt
     * @return
     * @throws Exception
     */
    BufferedImage createBusinessCards(Integer userId, String nickName, String headImgUrl, String qrCodeUrl, String fileExt) throws Exception;

    /**
     * 发送消息
     *
     * @param fromUserName
     * @param message
     * @param accessToken
     */
    void sendServiceMessage(String fromUserName, String msgType, String message, String accessToken);

    String getOpenId(String redirectUrl, String attach, HttpServletRequest request) throws UnsupportedEncodingException;

    String responseOpenId(HttpServletRequest request);


    /**
     * @return 获取令牌
     * @throws IOException
     */
    String getComponentAccessToken(String appId, String appSecret) throws IOException;

    String getUserInfo(String redirectUrl, String attach, HttpServletRequest request, String wapBackEndUrl) throws UnsupportedEncodingException;

    String responseUserInfo(HttpServletRequest request) throws UnsupportedEncodingException;

    JSONObject getUserInfo(String accessToken, String openId);

    /**
     * 保存临时素材
     */
    String mediaUpload(String authorizerToken, File file, String type);

    String SendTemplateMessage(JSONObject jsonObject);

}
